﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Technewlogic.FileXChange.Common;

namespace Technewlogic.FileXChange
{
	public partial class Service : System.Web.UI.Page
	{
		private FileUploadHelper _fileUploadHelper;

		protected void Page_Load(object sender, EventArgs e)
		{
			// Files to save from upload?
			try
			{
				Response.Clear();

				_fileUploadHelper = new FileUploadHelper(this.Request);
				FileMethod method = FileMethod.Parse(Request.QueryString[Constants.QueryStringMethod]);
				if (method == FileMethod.Put)
				{
					if (_fileUploadHelper.TrySaveFileFromRequest())
						Response.Write("File uploaded.");
					else
						Response.Write("No file to upload.");
				}
				else if (method == FileMethod.Get)
				{
					throw new NotImplementedException("Getting files is not implemented.");
				}
				else if (method == FileMethod.Delete)
				{
					_fileUploadHelper.DeleteFile();
					Response.Write("File deleted.");
				}
			}
			catch (Exception ex)
			{
				Response.Write("Error: " + ex.Message);
			}
		}
	}
}
